package com.example.second_home_work

import android.os.Bundle
import android.widget.Button
import android.widget.LinearLayout
import android.widget.Spinner
import android.widget.TextView
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity


class MainActivity : AppCompatActivity() {
    private val expert = ProgramExpert()
    private lateinit var container: LinearLayout
    private lateinit var addButton:Button

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_main)

        val button = findViewById<Button>(R.id.button)
        val spinner = findViewById<Spinner>(R.id.spinner)
        val textView = findViewById<TextView>(R.id.textView)

       container = findViewById(R.id.container)
        addButton = findViewById(R.id.button1)


        button.setOnClickListener{
            textView.text = expert.getLanguage(spinner.selectedItem.toString())
        }

        addButton.setOnClickListener{
            addTextView()
        }

    }
    private  fun addTextView(){
        val textView = TextView(this).apply {
            this.text = "这是新的视图 :${container.childCount+1}"
            setPadding(8,8,8,8)
        }
        container.addView(textView)
    }
}